<?


JCAT_Package::ImportClass( ROOT_PATH.'Classes/Coder/class.CoderDocBase.php') ;

abstract class DocumentDoc extends CoderDocBase implements IJCATMVCObject
{
	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$sPath=''	string	What's this Parameter ?
	 * @return	array
	 */
	public function DocumentDoc($sName,$sPath='')
	{
		$this->CoderDocBase( $sName, $sPath ) ;
		
		// 初始化文档结构  :::::::::;
		// 所拥有的 子控制器/文档/视图
		$aSubDoc = new JCATMVCObjectContainerDoc('MVCChildren',JCATMVCObjectContainerDoc::OBJECT_TYPE_DOCUMENT) ;
		$this->AddDocument($aSubDoc,'MVCChildren') ;
		
		
	}
	/**
	 * what's this
	 * 
	 * @access	public
	 * @static 
	 * @return	string
	 */
	public function GetKindIcon($nSize=16)
	{$nSize ;
		return ROOT_PATH.'Resource/Image/Document.24x24.png' ;
	}
	
	public function GetObjectChildrenDoc()
	{
		return $this->GetDocument('MVCChildren') ;
	}
	
	
	
	// 创建代码 /////////////////////////////////////////////
	
	
	/**
	 * 将序列化以后的内容存入到 文档
	 * 
	 * @access	protected
	 * @param	$sPath				文件路径
	 * @param	$sByteContents		字节内容
	 * @param	$bAsBinary			作为二进制存储
	 * @return	bool
	 */
	protected function SaveToFile( $sPath, $sByteContents, $bAsBinary=false )
	{
		// 调用父类
		parent::SaveToFile( $sPath, $sByteContents, $bAsBinary ) ;

		foreach ($this->arrCodeBlocks as $sCodeBlockName=>$nTabNum)
		{
			$sMethodName = 'CreateCode_'.str_replace(' ','',$sCodeBlockName) ;
			CoderDocBase::WirteUnmodifiableBlock($sPath,$sCodeBlockName,$this->$sMethodName(),CoderDocBase::UnmodifiableBlockKind_Code,$nTabNum) ;
		}

		// 完成 返回 
		return true ;
	}


	abstract public function CreateCode_CallParentConstruct() ;
	
	public function CreateCode_DocumentChildren()
	{
		$aSubDoc = $this->GetObjectChildrenDoc() ;
		$arrDocs = $aSubDoc->Get('Children') ;
	
		if(!count($arrDocs))
		{
			return '' ;
		}

		$sTab = str_repeat("\t",2) ;
		$arrCodeLine[] = "{$sTab}// ".JCAT_Language::Sentence('创建并添加子文档') ;
		$arrCodeLine[] = "{$sTab}\$sCurrentDirectory = dirname(__FILE__).'/' ;" ;

		foreach ($arrDocs as $arrOneDoc)
		{
			$sSubDocName = $arrOneDoc[TreeJCATMVCObject::CLM_NAME] ;
			$sSubDocPath = $arrOneDoc[TreeJCATMVCObject::CLM_PATH] ;

			$arrCodeLine[] = "{$sTab}JCAT_Package::ImportClass('{$sSubDocName}',\$sCurrentDirectory.'{$sSubDocPath}') ;" ;
			$arrCodeLine[] = "{$sTab}\$this->AddDocument(new {$sSubDocName}()) ;" ;
		}

		return implode("\r\n",$arrCodeLine) ;
	}
	
	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	string
	 */
	public function CreateCode_ForControllerMainRun()
	{
		$sTab = str_repeat("\t",2) ;
		$arrCodeLines = array() ;
		
		$sName = $this->GetName() ;
		
		$arrCodeLines[] = "{$sTab}// " . JCAT_Language::Sentence('执行子控制器  %s',$sName) ;
		$arrCodeLines[] = "{$sTab}\$aChildController = \$this->GetController('{$sName}') ;" ;
		$arrCodeLines[] = "{$sTab}JCAT_ASSERT::ASSERT_INSTANCE(\$aChildController,'JCAT_IController',JCAT_Language::Sentence('名为 %s 的子控制器未定义','{$sName}')) ;" ;
		
		$arrCodeLines[] = "{$sTab}\$aChildController->MainRun(& \$arrArg) ;" ;

		return implode("\r\n",$arrCodeLines) ;
	}


	protected $arrCodeBlocks = array(
				'Call Parent Construct' =>2
				, 'Document Children' =>2
	) ;
}

JCAT_Package::ImportClass('JCAT_UIHtml',JCAT::PACKAGE_UIHTML) ;
?>